#include "CMessageSystem.h"

CMessenger *CMessenger::GetInstance()
{
	static CMessenger instance;
	return &instance;
}

void CMessenger::SendMsg(string szID, void *pSender, void *pArgs)
{
	tMessage Message;
	Message.SetParams(szID, pSender, pArgs);
	m_qMessages.push(Message);
}

void CMessenger::PostMsg(string szID, void *pSender, void *pArgs)
{
	m_pfHandler(szID, pSender, pArgs);
}

void CMessenger::ProcessMessages()
{
	if (!m_pfHandler)
	{
		while (!m_qMessages.empty())
			m_qMessages.pop();
		return;
	}

	while (!m_qMessages.empty())
	{
		m_pfHandler(m_qMessages.front().m_szMessageID, m_qMessages.front().m_pSender, m_qMessages.front().m_pArgs);
		m_qMessages.pop();
	}
}

void CMessenger::ClearMessages()
{
	while (!m_qMessages.empty())
		m_qMessages.pop();
}